<?php
	include_once("Database.inc");
	
class Ministry {

	public $id;
	public $description;

	public static function getAllMinistries() {
		$m = array();
		
		$query = $GLOBALS["DB"] -> doQuery("SELECT MINISTRYID, MINISTRYDESC FROM MINISTRIES ORDER BY MINISTRYID");
		
		while ($row = mssql_fetch_array($query)) {
			array_push($m, Ministry::getMinistryFromArray($row));
		}
		
		return $m;
	}
	
	public static function getMinistry($id) {
		$query = $GLOBALS["DB"] ->
			doQuery("SELECT MINISTRYID, MINISTRYDESC FROM MINISTRIES WHERE MINISTRYID=$id");
	
		if ($row = mssql_fetch_array($query)) {
			return Ministry::getMinistryFromArray($row);	
		} else {
			return null;
		}
	}

	protected static function getMinistryFromArray($array) {
		$m = new Ministry();
		
		$m->id = $array[0];
		$m->description = $array[1];
		
		return $m;
	}	
}